#include <bits/stdc++.h>

using namespace std;

int n, m, l, vlim, p[100005];

double s_lim (int v0, int a, int vlim){
    return (vlim * vlim - v0 * v0) * 0.5 / (a * 1.0);
}

int binarysearch (int val) {
    int l = 1, r = m;
    while (l < r){
        int mid = l + r >> 1;
        if (p[mid] < val) l = mid + 1;
        else r = mid;
    }
    return p[l] == val? l: 0;
}

struct node{
    int d, v, a;
    double overspeedL,overspeedR;
    void init(){
        if (a == 0){
            if (v <= vlim) overspeedL = overspeedR = -1.0;
            else overspeedL = (double)d, overspeedR = (double)l;
        } else {
            if (a > 0){
                overspeedL = s_lim(v, a, vlim) + (double)d + 0.1;
                overspeedR = (double)l;
            } else {
                overspeedL = (double)d;
                overspeedR = s_lim(v, a, vlim) + (double)d - 0.1;
            }
        }
    }
}vechile[100005];

void solve () {
    cin >> n >> m >> l >> vlim;
    for (int i = 1; i <= n; i++){
        cin >> vechile[i].d >> vechile[i].v >> vechile[i].a;
        vechile[i].init();
    }
    for (int i = 1; i <= m; i++) cin >> p[i];
    int ans = 0, tmp; bool f = false;
    for (int k = 1; k <= n; k++){
        for (int i = ceil(vechile[k].overspeedL); i <= floor(vechile[k].overspeedR); i++){
            if(binary_search(p + 1, p + m + 1, i)){ f = true; break; }
        }
        ans += f;
    }
    cout << ans << ' ';
    //?
    cout << 0 << endl;
    return ;
}

int main () {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}
